Skip to content

Conversation

@AndreiEres
Copy link
Contributor

@AndreiEres AndreiEres commented Nov 25, 2025

Description

Internal submittion result type changed to keep more information, which should be useful for RPC clients.

Application-level errors moved from JSON-RPC transport errors into the result type for statement_submit RPC method to help clients distinguish between submission outcomes instead of parsing error strings.

Runtime API wasn't changed.

Integration

Breaking Change - statement_submit now returns StatementSubmitResult enum instead of ().

Review Notes

Submission outcomes now return as Ok(result) with status field. Only infrastructure failures (database errors, decode errors) remain as JSON-RPC errors.

NetworkPriority removed as we never used it, reputation changes adjusted.

@carlosala
Copy link
Contributor

Wayyyy better than before, thank you for the effort! 😉

Copy link
Contributor

@carlosala carlosala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀

@carlosala
Copy link
Contributor

Probably the next step is to rethink the whole API, reducing the surface and providing clear endpoints 👍🏻

@AndreiEres
Copy link
Contributor Author

AndreiEres commented Nov 27, 2025

I looked at all cases where we use SubmitResult (internal, not RPC types). I think we could be more user-friendly by showing what exactly happened and helping users decide how to fix the problem. Then we can adjust RPC types according to that.

Current SubmitResult

  • New(NetworkPriority)
    • Successfully validated and stored
      • ISSUE: it has NetworkPriority but we never set anything except High
  • Known
    • Statement already exists
  • KnownExpired
    • Statement exists but expired, can't happen during submission over RPC
  • SubmitResult::Ignored
    • Encoded size > MAX_STATEMENT_SIZE
    • Data size > validation.max_size
    • Priority ≤ existing channel message priority
    • Priority too low, can't evict enough messages (account limits)
    • Store full (exceeds max_total_size or max_total_statements)
  • SubmitResult::Bad
    • No statement proof
    • Bad statement proof
  • InternalError(Error)
    • Validation internal error
    • Database commit failed

Proposed SubmitResult

enum SubmitResult {
	New,                       // Submitted
	Known,                     // Already exists
	KnownExpired,              // Already exists but expired, never appears in RPC
	Invalid(InvalidReason),    // Statement is invalid
	Rejected(RejectionReason), // Statement rejected, try again with different parameters
	InternalError(Error),      // Internal error
}

enum InvalidReason {
	NoProof,
	BadProof,
	EncodingTooLarge { submitted_size: usize, max_size: usize },
}

enum RejectionReason {
	DataTooLarge { submitted_size: usize, available_size: usize },
	ChannelPriorityTooLow { submitted_priority: u32, min_priority: u32 },
	AccountFull { submitted_priority: u32, min_priority: u32 },
	StoreFull { submitted_priority: u32, min_priority: u32 },
}

@AndreiEres
Copy link
Contributor Author

/cmd prdoc --audience node_dev --bump major

@AndreiEres AndreiEres added the T0-node This PR/Issue is related to the topic “node”. label Nov 28, 2025
pub const GOOD_STATEMENT: Rep = Rep::new(1 << 7, "Good statement");
/// Reputation change when a peer sends us a bad statement.
pub const BAD_STATEMENT: Rep = Rep::new(-(1 << 12), "Bad statement");
pub const GOOD_STATEMENT: Rep = Rep::new(1 << 8, "Good statement");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean up. We never used the old GOOD_STATEMENT, so I removed it. But since we have only EXCELENT_STATEMENT, no need to keep it excelent, just good is ok

use std::sync::Arc;

/// Maps the internal InvalidReason to the RPC API InvalidReason type.
fn map_invalid_reason(reason: sp_statement_store::InvalidReason) -> InvalidReason {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: they seem to have the same invariant, so probably can be a From implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't add From here, either I didn't want to bring extra crates to dependencies.

@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/19819198522
Failed job name: test-linux-stable-no-try-runtime

Low,
/// Reason why a statement was rejected from the store.
#[derive(Debug, Eq, PartialEq)]
pub enum RejectionReason {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you duplicated these types? Because of serde? Make it an optional dependency.

@AndreiEres AndreiEres added this pull request to the merge queue Dec 2, 2025
@AndreiEres AndreiEres removed this pull request from the merge queue due to a manual request Dec 2, 2025
@AndreiEres AndreiEres enabled auto-merge December 2, 2025 10:36
@AndreiEres AndreiEres added this pull request to the merge queue Dec 2, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 2, 2025
@bkchr bkchr added this pull request to the merge queue Dec 2, 2025
Merged via the queue into master with commit 6de451a Dec 3, 2025
252 of 254 checks passed
@bkchr bkchr deleted the AndreiEres/sss-rpc-types branch December 3, 2025 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T0-node This PR/Issue is related to the topic “node”.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants